package com.ruoyi.game.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.game.api.domin.GameItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.game.service.IGameItemService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物品Controller
 *
 * @author qidian
 * @date 2022-05-06
 */
@RestController
@RequestMapping("/item")
public class GameItemController extends BaseController
{
    @Autowired
    private IGameItemService gameItemService;

    /**
     * 查询物品列表
     */
    @RequiresPermissions("game:item:list")
    @GetMapping("/list")
    public TableDataInfo list(GameItem gameItem)
    {
        startPage();
        List<GameItem> list = gameItemService.selectGameItemList(gameItem);
        return getDataTable(list);
    }

    /**
     * 导出物品列表
     */
    @RequiresPermissions("game:item:export")
    @Log(title = "物品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GameItem gameItem)
    {
        List<GameItem> list = gameItemService.selectGameItemList(gameItem);
        ExcelUtil<GameItem> util = new ExcelUtil<GameItem>(GameItem.class);
        util.exportExcel(response, list, "物品数据");
    }

    /**
     * 获取物品详细信息
     */
    @RequiresPermissions("game:item:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gameItemService.selectGameItemById(id));
    }

    /**
     * 新增物品
     */
    @RequiresPermissions("game:item:add")
    @Log(title = "物品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GameItem gameItem)
    {
        return toAjax(gameItemService.insertGameItem(gameItem));
    }

    /**
     * 新增物品
     */
    @RequiresPermissions("game:item:add")
    @Log(title = "物品", businessType = BusinessType.INSERT)
    @PostMapping("batch")
    public AjaxResult add(@RequestBody List<GameItem> gameItems)
    {
        gameItemService.insertGameItem(gameItems);
        return AjaxResult.success();
    }

    /**
     * 修改物品
     */
    @RequiresPermissions("game:item:edit")
    @Log(title = "物品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GameItem gameItem)
    {
        return toAjax(gameItemService.updateGameItem(gameItem));
    }

    /**
     * 删除物品
     */
    @RequiresPermissions("game:item:remove")
    @Log(title = "物品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gameItemService.deleteGameItemByIds(ids));
    }
}
